local function rows(conn, cmd)
    local cur = conn:execute(cmd)
    return function ()
      return cur:fetch()
    end
end

local function main(conn, msg)
    local levelend,levelstart = msg['levelend'], msg['levelstart']
    local sql = string.format("SELECT `name`, `level` FROM `snap_user` WHERE `level` BETWEEN %s AND %s", levelstart, levelend)
    local data = {}
    for name, level in rows(conn, sql) do
        local snap = {}
        snap.name = name
        snap.level = level
        data[#data+1] = snap
    end
    return data
end

return main
